from autoframe.common.base import *

'''
    定位元素
'''


class OrderLocation(Base):

    def merchandise_location(self, location):  # 商品 定位
        self.click(location)

    def settlement(self, ):  # 立即购买按钮 定位
        self.click((By.CLASS_NAME, 'td1'))

    def settlement_go(self, ):  # 结算按钮 定位
        self.click((By.XPATH, '/html/body/div[6]/div[1]/table/tbody/tr/td[2]/a/img'))

    def distribution_mode_post_office(self):  # 邮寄方式  邮政平邮 定位
        self.click((By.XPATH, '//*[@id="paymentTable"]/tbody/tr[2]/td[1]/input'))

    def payment_method_balance(self):  # 支付方式  余额支付  定位
        self.click((By.XPATH, '//*[@id="theForm"]/div[15]/div[2]/input[1]'))

    def payment_method_bank(self):  # # 支付方式  银行支付  定位
        self.click((By.XPATH, '//*[@id="paymentTable"]/tbody/tr[3]/td[1]/input'))

    def place_order(self):  # 提交订单按钮
        self.click((By.XPATH, '//*[@id="theForm"]/div[15]/div[2]/input[1]'))

    def H6_text(self):  # 获取 购买成功后返回的订单
        return self.get_text((By.XPATH, '/html/body/div[6]/div/h6/font'))

    def list_text(self):  # 获取订单管理最新的订单号
        self.get('http://172.16.140.57/ecshop/user.php?act=order_list')
        return self.get_text((By.XPATH, '/html/body/div[6]/div[2]/div/div/div/table/tbody/tr[1]/td[1]/a'))

    '''
        操作方法
    '''

    def generate_order_login(self):  # 登入账号
        self.get('http://172.16.140.57/ecshop/')
        self.click((By.XPATH, '/html/body/div[1]/div/div[2]/div[1]/a'))
        self.send_keys((By.NAME, 'username'), 'yang1234')
        self.send_keys((By.NAME, 'password'), '123456')
        self.click((By.NAME, 'submit'))
        time.sleep(3)

    def generate_order_01(self):  # 支付流程  炫彩翻页保护套-邮政平邮-余额支付
        self.merchandise_location((By.XPATH, '/html/body/div[6]/div/div/div[2]/div[2]/div/a[2]'))  # 炫彩翻页保护套
        self.settlement()  # 点击购买按钮
        self.settlement_go()  # 点击结算按钮
        self.distribution_mode_post_office()  # 选择邮政平邮
        self.payment_method_balance()  # 选择余额支付
        self.place_order()  # 提交订单

    def generate_order_02(self):  # # 支付流程  炫彩翻页保护套-邮政平邮-银行汇款/转帐

        self.merchandise_location((By.XPATH, '/html/body/div[6]/div/div/div[2]/div[2]/div/a[2]'))  # 炫彩翻页保护套
        self.settlement()  # 点击购买按钮
        self.settlement_go()  # 点击结算按钮
        self.distribution_mode_post_office()  # 选择邮政平邮
        self.payment_method_bank()  # 选择银行卡支付
        self.place_order()  # 提交订单
